from openpyxl.workbook import Workbook
# wb=Workbook()
# ws=wb.worksheets[0]
# ws.title="写入公式"
# c1=ws.cell(1,1)
# c2=ws.cell(1,2)
# c3=ws.cell(2,1)
# c4=ws.cell(2,2)
# c1.value=10
# c2.value=5
# c3.value=8
# c4.value=2
# c5=ws.cell(1,3)
# c6=ws.cell(2,3)
# c5.value="=A1*B1"
# c6.value="=A2*B2"
# # cx=ws.cell(3,9)
# # res=cx.coordinate
# # print(res)
# wb.save("files/写入公式.xlsx")


wb=Workbook()
ws=wb.worksheets[0]
ws.title="写入公式"
list_01=[15,10,18,13,20,12]
list_02=[8,7,1,4,5,6]
for idx,(val1,val2) in enumerate(zip(list_01,list_02),1):
    c1 = ws.cell(idx, 1, value=val1)
    c2 = ws.cell(idx, 2, value=val2)
    c3 = ws.cell(idx, 3, value=f"={c1.coordinate}*{c2.coordinate}")
# for idx in range(len(list_01)):
#     c1=ws.cell(1,idx+1)
#     c2=ws.cell(2,idx+1)
#     c3=ws.cell(3,idx+1)
#     address1=c1.coordinate
#     address2=c2.coordinate
#     c1.value=list_01[idx]
#     c2.value=list_02[idx]
#     c3.value=f"={address1}*{address2}"
    # print(c1.value,c2.value)
    # print(address1,address2)
    print(c1.value,c2.value,c3.value)

wb.save("files/写入公式.xlsx")



